package com.study.dsa.demo.structure.recursion;

import org.junit.Test;

import java.util.Arrays;

public class RecursionTest {

    @Test
    public void test0() {
        //for循环阶乘
        Recursion.getFactorialFor(4);
    }

    @Test
    public void test1() {
        //递归阶乘
        Recursion.getFactorialRecursion(4);
    }

    @Test
    public void test2() {
        //找到目标值返回数组下标，找不到返回-1
        int[] array = {1, 2, 3, 4, 5};
        System.out.println(Recursion.findTwoPoint(array, 3));
    }

    @Test
    public void test3() {
        //递归二分查找
        int[] array = {1, 2, 3, 4, 5};
        System.out.println(Recursion.search(array, 3, 1, 5));
    }

    @Test
    public void test4() {
        //汉诺塔问题
        Recursion.move(3, "A", "B", "C");
    }

    @Test
    public void test5() {
        //传入两个有序数组a和b，返回一个排好序的合并数组
        int[] array1 = {1, 2, 6, 8, 5};
        int[] array2 = {10, 7, 3, 4, 9};
        int[] array3 = Recursion.sort(array1, array2);
        Arrays.stream(array3).forEach(System.out::println);
    }

    @Test
    public void test6() {
        //归并排序
        int[] c = {2, 7, 8, 3, 1, 6, 9, 0, 5, 4};
        c = Recursion.mergeSort(c, 0, c.length - 1);
        System.out.println(Arrays.toString(c));
    }

    @Test
    public void test7() {
        System.out.println(Recursion.pow(1, 2));
    }

    /**
     * 背包问题
     */
    @Test
    public void test8() {
        int array[] = {11, 9, 7, 6, 5};
        int total = 20;
        Knapsack k = new Knapsack(array);
        k.knapsack(total, 0);
    }

    /**
     * 组队
     */
    @Test
    public void test9() {
        char[] persons = {'A', 'B', 'C', 'D', 'E'};
        Combination cb = new Combination(persons);
        cb.showTeams(3);
    }
}
